//自动生成于：2021/3/3 15:28:54
namespace StarForce.Hotfix
{

	public partial class DialogPage : HotfixUGuiForm
	{
		private DialogParams m_DialogParams;
		
		public override void OnInit(StarForce.HotfixUGuiForm uiFormLogic,object userdata)
		{
			base.OnInit(uiFormLogic, userdata);

			GetBindComponents(uiFormLogic.gameObject);
			
			m_Btn_Left.onClick.AddListener(Left);
			m_Btn_Right.onClick.AddListener(Right);
			m_Btn_Center.onClick.AddListener(Right);
			m_Btn_Mask.onClick.AddListener(MaskClick);
		}

		public override void OnOpen(object userdata)
		{
			base.OnOpen(userdata);
			if (userdata is DialogParams dialog)
			{
				m_DialogParams = dialog;
				m_Txt_Message.text = m_DialogParams.Message;
				if (dialog.Mode == 1)
				{
					m_Txt_CenterText.text = m_DialogParams.RightText;
					m_Btn_Center.gameObject.SetActive(true);
					m_Btn_Left.gameObject.SetActive(false);
					m_Btn_Right.gameObject.SetActive(false);
				}
				else
				{
					m_Txt_LeftText.text = m_DialogParams.LeftText;
					m_Txt_RightText.text = m_DialogParams.RightText;
					m_Btn_Center.gameObject.SetActive(false);
					m_Btn_Left.gameObject.SetActive(true);
					m_Btn_Right.gameObject.SetActive(true);
				}
				
			}
		}

		public void MaskClick()
		{
			if (m_DialogParams.Close)
			{
				Close();
			}
		}
		
		private void Left()
		{
			m_DialogParams?.OnClickLeft?.Invoke();

			if (m_DialogParams != null && m_DialogParams.Close)
			{
				Close();
			}
		}

		private void Right()
		{
			m_DialogParams?.OnClickRight?.Invoke();
			
			if (m_DialogParams != null && m_DialogParams.Close)
			{
				Close();
			}
		}
		
		public override void OnClose(bool isShutdown, object userData)
		{
			base.OnClose(isShutdown, userData);
			m_DialogParams = null;
		}
	}
}
